<template>
  <div id="counter_result_out_sc" class="counter-result-sc">
    <canvas-to-img v-if="codeUrl">
      <img src="../images/Banner_2x.jpg" class="banner-img" slot="img">
      <p class="p1">请凭此二维码于{{day}}前至以下专柜</p>
      <p class="p2">领取香奈儿山茶花润泽水感乳液体验装一份</p>
      <p class="p3">{{ storeName }}</p>
      <p class="p4">{{ addressResult }}</p>
      <img :src="codeUrl" class="qr" slot="img">
      <div>
        <p class="p5-out">长按可保存二维码至相册，每人限领一份，限本人领取，领完即止</p>
      </div>
      <p class="p5-save">长按可保存二维码至相册，每人限领一份，限本人领取，领完即止</p>
      <p class="p6">
        如有问题，欢迎拨打客服热线
        <a href="tel:4009-555-888">4009-555-888</a>
      </p>
      <div>
        <p class="p6 p6-click">
          如有问题，欢迎拨打客服热线
          <a href="tel:4009-555-888">4009-555-888</a>
        </p>
      </div>
    </canvas-to-img>
    <!-- <div id="code"></div> -->
    <canvas id="code" style="display:none"></canvas>
  </div>
</template>

<script>
import CanvasToImg from "@/components/CanvasToImg";
import QRCode from "qrcode";
import utils from "@/utils";
export default {
  props: ["storeName", "address", "channel", "type"],
  data() {
    return {
      codeUrl: "",
      qrShow: false,
      pageImgReady: false,
      contentResultUrl: "",
      day: ""
    };
  },
  components: {
    CanvasToImg
  },
  computed: {
    addressResult() {
      if (!this.address) return "";
      const result = this.address.split(" ");
      return result[2];
    }
  },
  created() {
    this.getDate();
  },
  mounted() {
    this.generateQrcode();
  },
  methods: {
    getDate() {
      console.log(this.type);
      if (this.type === "ds") {
        this.day = "5月26日";
      } else {
        this.day = "5月16日";
      }
    },
    generateQrcode() {
      const discern =
        this.$route.query.discern ||
        localStorage.getItem("camellia-sample-discern");
      const host = `https://vip.chanel.cn/index.php?s=/addon/Api/Activity/hx/campaignid/OSHB9049/sign/${discern}.html`;
      QRCode.toCanvas(document.getElementById("code"), host, error => {
        if (error) console.error(error);
        this.codeUrl = document.getElementById("code").toDataURL("image/jpeg");
      });
    }
  }
};
</script>

<style lang="less" scoped>
p {
  font-size: 14px;
  color: #666;
  position: absolute;
  z-index: 1;
  text-align: center;
  width: 100%;
  // opacity: 0;
}

img {
  position: absolute;
  // opacity: 0;
  z-index: 1;
}

.p1 {
  top: 330px;
  color: #666;
}
.p2 {
  top: 356px;
}
.p3 {
  top: 382px;
  font-size: 16px;
  color: #000;
}
.p4 {
  top: 410px;
}

.p5-out {
  top: 540px;
  font-size: 12px;
}

.p5-save {
  display: none;
  top: 540px;
  font-size: 12px;
}

.p6 {
  top: 560px;
  font-size: 12px;
  > a {
    color: #666;
    line-height: 1;
    display: inline-block;
    border-bottom: 1px solid #666;
  }
}
.p6-click {
  opacity: 0;
  z-index: 3;
}

.qr {
  top: 449px;
  left: 50%;
  width: 71px;
  margin: 0 auto;
  transform: translateX(-50%);
}
.banner-img {
  top: 0;
  width: 100%;
}
.counter-result-sc {
  height: 100%;
  position: relative;
}

#code {
  display: none;
}
</style>
